define([
    'SelectTree', './demo/dialogForm'
], function(SelectTree, dialogForm) {
    'use strict';
    
    var currentPage = {
        setListener: function(){
            $(document).on('click', '#demo_content .btn', function(e){
                e.preventDefault();
                var _this = e.target;
                var type = $(_this).data('type');
                if(type == 'toast'){
                    $.toast({
                        heading: 'Information',
                        text: 'Now you can add icons to generate different kinds of toasts',
                        showHideTransition: 'slide'
                    });
                }
            })
        },
        showTree: function(){
            var treeData = [
                { name: '1', id: 1 },
                { name: '2', id: 2, children: [
                    { name: '2-1', id: 21, chkDisabled: true },
                    { name: '2-2', id: 22 },
                    { name: '2-3', id: 23 },
                    { name: '2-4', id: 24 },
                    { name: '2-5', id: 25 }
                ] },
                { name: '3', id: 3 },
                { name: '4', id: 4, children: [
                    { name: '4-1', id: 41, chkDisabled: true },
                    { name: '4-2', id: 42 },
                    { name: '4-3', id: 43 },
                    { name: '4-4', id: 44 },
                    { name: '4-5', id: 45 }
                ] },
                { name: '5', id: 5 }
            ];
            currentPage.selectTree = new SelectTree({
                id: 'treeBox',
                label: '自定义树形',
                treeConfig: {
                    check: {
                        enable: true,
                        chkStyle: 'checkbox',
                        chkboxType: { "Y": "", "N": "" }
                    },
                    view: {
                        showIcon: false,
                        showLine: true,
                        showTitle: true
                    }
                },
                searchConfig:{
                    enable: true,
                    level: 0,
                    // filter: function(node, text){
                    //     return node.level > 0 ? false : true;
                    //     // 自定义搜索方法，此时其他搜索配置条件将失效，返回值true/false
                    // }
                },
                showLevel: 2,
                nameField: 'name',
                valueField: 'id',
                value: [{ name: '4-2', id: 42 }],
                treeData: treeData
            })
        },
        showDialogForm: function(){
            dialogForm.init({
                id: 'dialogForm',
                data: []
            })
        },
        init: function(){
            console.log('demo');
            currentPage.setListener();
            currentPage.showTree();
            currentPage.showDialogForm();
        }
    }

    return function(){
        return {
            htmlStr: (function(){
                var str = '<div id="demo_content">'
                    + '<div><span class="loading"></span></div>'
                    + '<div><a class="btn" data-type="toast">toast</a></div>'
                    + '<div class="tree-box"><div id="treeBox"></div><div id="myTree"></div></div>'
                    + '<div id="dialogForm"></div>'
                    + '</div>';
                return str;
            })(),
            render: function(){
                currentPage.init();
            }
        }
    }
});